﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing;

namespace Kinect
{
    public class Blob
    {

        // mean color of the blob
        private Color colorMean = Color.Black;
        // color's standard deviation of the blob
        private Color colorStdDev = Color.Black;

        public Point AreaCounter = new Point();


        public double ScaleX;
        public double ScaleY;

        /// <summary>
        /// Blob's ID in the original image.
        /// </summary>
        public int ID;

        /// <summary>
        /// Blob's area.
        /// </summary>
        /// 
        /// <remarks><para>The property equals to blob's area measured in number of pixels
        /// contained by the blob.</para></remarks>
        /// 
        private double area;
        public double Area
        {
            get
            {
                return area ;
            }
            set
            {
                area = value;
            }
        }

        public double aspectRatio
        {
            get
            {
                if (Height > Width)
                {
                    return Height / Width;
                }
                else
                {
                    return Width / Height;
                }
            }
        }
        /// <summary>
        /// Blob's fullness, [0, 1].
        /// </summary>
        /// 
        /// <remarks><para>The property equals to blob's fullness, which is calculated
        /// as <b>Area / ( Width * Height )</b>. If it equals to <b>1</b>, then
        /// it means that entire blob's rectangle is filled by blob's pixel (no
        /// blank areas), which is true only for rectangles. If it equals to <b>0.5</b>,
        /// for example, then it means that only half of the bounding rectangle is filled
        /// by blob's pixels.</para></remarks>
        /// 
        public double Fullness
        {
            get 
            {
                return Area / (Width * Height);
            }
            
        }

        /// <summary>
        /// Blob's center of gravity point.
        /// </summary>
        /// 
        /// <remarks><para>The property keeps center of gravity point, which is calculated as
        /// mean value of X and Y coordinates of blob's points.</para></remarks>
        /// 
        public Point CenterOfGravity
        {
            get 
            {
                return new Point((int)( (AreaCounter.X * ScaleX) / Area), (int)( (AreaCounter.Y * ScaleY) / Area) );
            }
        }

        public int x1;
        public int y1;
        public int x2;
        public int y2;

        public double Width
        {
            get
            {
                return (x2 - x1 + 1) * ScaleX;
            }
        }

        public double Height
        {
            get
            {
                return (y2 - y1 + 1) * ScaleY;
            }
        }


        internal Blob(int id)
        {
            this.ID = id;
        }

    }
}
